package com.xdf.ecommerce.stream.customChannel;

import com.alibaba.fastjson.JSON;
import com.xdf.ecommerce.vo.SCSMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

/**
 * @author chanchaw
 * @create 2025-11-06 15:50
 */
@Slf4j
@RequiredArgsConstructor
@EnableBinding(MyChannel.class)// 绑定自定义信道的接口类，即通过自定义信道发送消息
public class MySendService {
    private final MyChannel myChannel;
    public void sendMessage(SCSMessage message){
        String msg = JSON.toJSONString(message);
        myChannel.ccOutput().send(MessageBuilder.withPayload(msg).build());
        log.info("使用自定义信道发送了消息：[{}]", msg);
    }
}
